<?php

/** libraries
 * http://docs.joomla.org/JToolBarHelper
 */

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class bgViewbg extends JView
{
    
	// Overwriting JView display method
	function display($tpl = null) 
	{
	   
	   $model = $this->getModel();
       
       $task = JRequest::getVar('task');
       switch($task){
        
            case 'error':
                $this->row = (object)JRequest::getVar('jform');
                $this->setLayout('a00910');
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','送信');
               	JToolBarHelper::cancel('cancel', 'キャンセル');
                JToolBarHelper::title('メールマガジン作成','new-privatemessage.png');
            break;
            
            case 'edit':
                $cid = JRequest::getVar('cid');
                $cid = is_array($cid) ? $cid[0] : $cid;
                if($cid){
                    $this->row = $model->load($cid);
                }else{
                    die('Not found');
                }
                
                // if mail is sent, only view
                if(isset($this->row) && $this->row->MAMA_FLAG == 3){
                    $this->setLayout('a00920');
                    //JToolBarHelper::back('戻る');
                    JToolBarHelper::cancel('cancel', '戻る');
                }else{
                    $this->setLayout('a00910');
                    JToolBarHelper::save2copy('savetemp','一時保存');
                    JToolBarHelper::save('save','送信');
                   	JToolBarHelper::cancel('cancel', 'キャンセル');
                }
                
                JToolBarHelper::title('メールマガジン編集','new-privatemessage.png');
                
                
                break;
            case 'add':
                JToolBarHelper::title('メールマガジン作成','new-privatemessage.png');
                JToolBarHelper::save2copy('savetemp','一時保存');
                JToolBarHelper::save('save','送信');
               	JToolBarHelper::cancel('cancel', 'キャンセル');
                
                $this->setLayout('a00910');
                
            break;
           
            default:
                
                
                //search
                $this->list['filter_search'] = &JRequest::getVar('filter_search');
                $this->list['status'] = &JRequest::getVar('status');
                
                // Get data from the model
                $this->rows =& $model->getAll($this->list);  
                $this->pagination =& $this->get('Pagination');
         
         
                $this->setLayout('a00900');
            
                JToolBarHelper::title( 'メールマガジン管理','new-privatemessage.png' );

                JToolBarHelper::addNew('add','作成');
            	JToolBarHelper::editList('edit', '編集');
            	JToolBarHelper::deleteList('', 'remove','削除');
                
       }
        
		parent::display($tpl);
       
	}
}




